package com.scau.hwadee.examination.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scau.hwadee.examination.entity.Examdate;
import com.scau.hwadee.examination.entity.Examsession;
import com.scau.hwadee.examination.entity.Majorplanversion;
import com.scau.hwadee.examination.entity.Unifiedexamschedule;
import com.scau.hwadee.examination.mapper.ExamdateMapper;
import com.scau.hwadee.examination.mapper.ExamsessionMapper;
import com.scau.hwadee.examination.mapper.MajorplanversionMapper;
import com.scau.hwadee.examination.mapper.UnifiedexamscheduleMapper;
import com.scau.hwadee.examination.service.ExaminationManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author YSY
 * @date 2019/8/1/15:58
 * description
 */
@Service
public class ExaminationManagementServiceImpl implements ExaminationManagementService {
    @Autowired
    private ExamdateMapper examdateMapper;

    @Autowired
    private ExamsessionMapper examsessionMapper;

    @Autowired
    private UnifiedexamscheduleMapper unifiedexamscheduleMapper;

    @Autowired
    private MajorplanversionMapper majorplanversionMapper;

    private DateFormat format = new SimpleDateFormat("HH:mm:ss");

    //根据考次编码获取时间编码
    @Override
    public String getByesIdForedTimecode(String esId) {
        return examdateMapper.selectByesIdForedTimecode(esId);
    }

    //显示MV_ID
    @Override
    public PageInfo<Majorplanversion> getAllMajorPlanVersion(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(majorplanversionMapper.listAllMajorPlanVersion(pageNum, pageSize));
    }

    //显示所有考次
    @Override
    public PageInfo<Examsession> getAllExamSessions(int pageNum, int pageSize, Integer state) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(examsessionMapper.selectAllExamSessions(pageNum, pageSize, state));
    }

    //添加考次
    @Override
    public int insertNewExamsession(Examsession examsession) {
        try {
            return examsessionMapper.insertSelective(examsession);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    //选择考次
    @Override
    public Examdate getExamDate(String esId) {
        return examdateMapper.selectByPrimaryKey(esId);
    }

    //添加考试日期
    @Override
    public int updateNewExamdate(Examdate examdate) {
        try {
            return examdateMapper.updateByPrimaryKey(examdate);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    //导入统考课表
    @Override
    public int insertunifiedExamScheduleByExcel(List<Unifiedexamschedule> unifiedExamSchedule) {
        try {
            return unifiedexamscheduleMapper.insertunifiedexamscheduleListByExcel(unifiedExamSchedule);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

}
